const logger = require('../utils/logger')

module.exports = async (ctx, next) => {
  const start = Date.now()
  logger.trace('request ', ctx.request.query, ctx.request.params, ctx.request.headers, ctx.request.body)
  await next()
  const end = Date.now()
  const duration = end - start
  logger.trace('response ', ctx.response.body)
  logger.trace('time spend ', duration + 'ms')
  ctx.set('X-Response-Time', duration + 'ms')
}